package com.daocao.jy.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.daocao.jy.R;
import com.lljjcoder.citypickerview.model.CityModel;
import com.lljjcoder.citypickerview.model.ProvinceModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class AddressSelectAdapter extends ItemAdapter<ProvinceModel, AddressSelectAdapter.DefaultHolder> {


    public AddressSelectAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_address_select, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ProvinceModel item = getItem(position);
        holder.txtAddress.setText(item.getName());
        holder.txtAddress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onChooseListener!=null){
                    onChooseListener.onClick(item.getCityList());
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_address)
        TextView txtAddress;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(ArrayList<CityModel> item);
    }
}
